<template>
  <div class="RaddarChart chart" ref="el" style="width: 100%;height: 300px;"></div>
</template>

<script setup>
import { ref, nextTick, onMounted, onBeforeUnmount } from 'vue'
import useResizeHook from "../hooks/useResizeHook.js"
import * as echarts from 'echarts'
import "echarts/theme/cool" // echarts theme

const el = ref(null)

let chart = null

const useResize = useResizeHook(chart)

onMounted(() => {
  nextTick(() => initChart())
})

onBeforeUnmount(() => {
  if (!chart) return
  chart.dispose()
  chart = null
})

function initChart() {
  chart = echarts.init(el.value, 'cool')
  chart.setOption({
    tooltip: {
      trigger: 'axis',
      axisPointer: { // 坐标轴指示器，坐标轴触发有效
        type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
      }
    },
    radar: {
      radius: '60%',
      center: ['50%', '40%'],
      splitNumber: 10,
      splitArea: {
        areaStyle: {
          color: 'rgba(127,95,132,.3)',
          opacity: 1,
          shadowBlur: 45,
          shadowColor: 'rgba(0,0,0,.5)',
          shadowOffsetX: 0,
          shadowOffsetY: 15
        }
      },
      indicator: [
        { name: '情商', max: 20000 },
        { name: '智商', max: 20000 },
        { name: '口嗨', max: 20000 },
        { name: '性格', max: 20000 },
        { name: '为人', max: 20000 },
        { name: '抠门', max: 20000 }
      ]
    },
    legend: {
      left: 'center',
      bottom: '10',
      data: ['Allocated Budget', 'Expected Spending', '谭栋']
    },
    series: [{
      type: 'radar',
      symbolSize: 0,
      areaStyle: {
        shadowBlur: 13,
        shadowColor: 'rgba(0,0,0,.2)',
        shadowOffsetX: 0,
        shadowOffsetY: 10,
        opacity: 1
      },
      data: [
        {
          value: [5000, 7000, 12000, 11000, 15000, 14000],
          name: 'Allocated Budget'
        },
        {
          value: [4000, 9000, 15000, 15000, 13000, 11000],
          name: 'Expected Spending'
        },
        {
          value: [5000, 5000, 22000, 5000, 5000, 22000],
          name: '谭栋'
        }
      ],
      animationDuration: 3000
    }]
  })

}
</script>

<style>
</style>